/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.ban.tools;

import cn.ac.iie.di.ban.commons.RuntimeEnv;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
//import org.apache.commons.codec.digest.DigestUtils;

/**
 *
 * @author wjt
 */
public class Tools {

//    public static String getColumnName(String getMongodbName, String table) {
//        HashMap<String, String> colMapping = RuntimeEnv.MQ_RS_COLUMNS.get(table);
//        if (colMapping.get(getMongodbName) != null) {
//            return colMapping.get(getMongodbName);
//        } else {
//            return null;
//        }
//    }

//    public static String getMd5(String str) {
//        if (str != null) {
//            return DigestUtils.md5Hex(str);
//        } else {
//            return "";
//        }
//    }

//    public static String maps2json(Map[] maps) {
//        String jsons = "";
//        for (Map map : maps) {
//            String json = JSONObject.toJSONString(map);
//            jsons += (json + ",");
//        }
//        if (maps.length > 0) {
//            jsons = jsons.substring(0, jsons.lastIndexOf(","));
//        }
//        jsons = "[" + jsons + "]";
//        return jsons;
//    }

    public static String[] getSData(Map[] m) {
        String[] newS = new String[m.length];
        if (m.length > 0) {
            for (int k = 0; k < m.length; k++) {
                HashMap singleM = (HashMap) m[k];
                newS[k] = (String) singleM.get("v");
            }
            return newS;

        } else {
            return newS;
        }
    }

    public static int getDay(long time) {
        long s = System.currentTimeMillis() / 1000;
        return 0;
    }

    public static int getMon(long time) {
        return 0;
    }

    public static int getYear(long time) {
        return 0;
    }

    public static int gethour(long time) {
        return 0;
    }

    public static void innerConvert(HashMap<String, Object> hm) {
        long time;
        if (hm.get("pt") != null) {
            time = (long) hm.get("pt");
        } else {
            time = 0;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(time * 1000));
        hm.put("year", calendar.get(Calendar.YEAR));
        hm.put("mon", calendar.get(Calendar.MONTH) + 1);
        hm.put("day", calendar.get(Calendar.DAY_OF_MONTH));
        hm.put("hr", calendar.get(Calendar.HOUR_OF_DAY));
    }

    public static void main(String[] args) {
        String cont = delSensitive("我们是一家人，嗨,我见过你么？你好，嗨楼~",new String[]{"一","么"});
        System.out.println(cont);
    }
    
    /*
    脱敏，把关键词替换成*
    */
    public synchronized static String delSensitive(String cont,String[] sensitiveWord){
        String contDisposed = cont;
        for(String word : sensitiveWord){
            contDisposed = contDisposed.replaceAll(word, "*");
        }
        return contDisposed;
    }
}
